#include "UARTX.h"

void USARTX_Init()
{
  GPIO_InitType GPIO_InitStructure;
  USART_InitType USART_InitStructure;


	RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO, ENABLE);
	/* Enable USART1 Clock */
	RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_USART3, ENABLE);

	/* Initialize GPIO_InitStructure */
	GPIO_InitStruct(&GPIO_InitStructure);
  
  /* Configure USART1 Tx as alternate function push-pull */
  GPIO_InitStructure.Pin = GPIO_PIN_10;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Alternate = GPIO_AF0_USART3;
  GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);


  /* Configure USART1 Rx as input floating */
	GPIO_InitStructure.Pin = GPIO_PIN_11;
	GPIO_InitStructure.GPIO_Pull      = GPIO_Pull_Up;
	GPIO_InitStructure.GPIO_Alternate = GPIO_AF5_USART3;
  GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);


	
	USART_InitStructure.BaudRate = 115200;
	USART_InitStructure.WordLength          = USART_WL_8B;
	USART_InitStructure.StopBits            = USART_STPB_1;
	USART_InitStructure.Parity              = USART_PE_NO;
	USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
	USART_InitStructure.Mode                = USART_MODE_RX | USART_MODE_TX;
  /* USART1 configuration */
	USART_Init(USART3, &USART_InitStructure);
  
	/* Enable the USART1 Receive interrupt */
  USART_ConfigInt(USART3, USART_INT_RXDNE, ENABLE);
	
  /* Enable USART1 */
  USART_Enable(USART3, ENABLE);	
}
